<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.io.IOException,java.io.PrintWriter,java.sql.Connection,java.sql.PreparedStatement,
java.sql.SQLException,java.sql.Statement,javax.servlet.ServletException,com.DbSQL,java.util.*;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% 
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String sno = request.getParameter("sno");
String password1 = request.getParameter("password1");
String name = request.getParameter("name");
String nickname = request.getParameter("nickname");
System.out.println(nickname);
String sex = request.getParameter("sex");
String birthday = request.getParameter("birthday");

String jian = request.getParameter("jian");

String pro = request.getParameter("pro");
String city = request.getParameter("city");
String county = request.getParameter("county");
String emotion = request.getParameter("emotion");
String phone = request.getParameter("phone");
String email=request.getParameter("email");
String account_type=request.getParameter("account_type");
String school_num = request.getParameter("school_num");
//String
String study_year = request.getParameter("study_year");
String grade = request.getParameter("grade");
String school = request.getParameter("school");
String speciality = request.getParameter("speciality");
if(account_type.equals("2"))
{
   study_year = "";
   grade = "";
   school="";
   speciality ="";
}
try{
	Connection conn = DbSQL.getCon();
	PreparedStatement preparedStatement = conn.prepareStatement("insert into user1("+
	"account,password,nickname,image,identify,level,score,school_num)"+"values(?,?,?,?,?,?,?,?)");
	preparedStatement.setString(1, sno);
	preparedStatement.setString(2, password1);
	preparedStatement.setString(3, nickname);
	preparedStatement.setString(4, "我很帅");
	preparedStatement.setString(5,account_type);
	preparedStatement.setString(6,"1");
	preparedStatement.setString(7,"0");
	preparedStatement.setInt(8,Integer.parseInt(school_num));//学校的编号需要重新找
	preparedStatement.executeUpdate();
	preparedStatement.close();
	PreparedStatement preparedStatement2 = conn.prepareStatement("insert into user2("+
	"account,email,name,sex,birthday,emotion,introduction,province,city,address,register_date,length_of_schooling,school,speciality)"
	+"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
	preparedStatement2.setString(1, sno);
	preparedStatement2.setString(2, email);
	preparedStatement2.setString(3, name);
	preparedStatement2.setString(4, sex);
	preparedStatement2.setString(5, birthday);
	preparedStatement2.setString(6,emotion);
	preparedStatement2.setString(7,jian);
	preparedStatement2.setString(8,pro);
	preparedStatement2.setString(9,city);	
	preparedStatement2.setString(10,county);
	Date day = new Date();
    String date = (day.getYear()+1900)+"_"+day.getMonth()+"_"+day.getDate();
	preparedStatement2.setString(11,date);
	preparedStatement2.setString(12,study_year);
	preparedStatement2.setString(13,school);
	preparedStatement2.setString(14,speciality);		
	preparedStatement2.executeUpdate();
	preparedStatement2.close();
	DbSQL.closeCon();
}catch(Exception e){
 e.printStackTrace();
}
System.out.println("注册成功！！");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>注册成功</title>
<script type="text/javascript">
alert("恭喜你注册成功!!");
window.location.href="/xiaonei1227/dl.jsp";
</script>
</head>
<body>
</body>
</html>